/*
 * This file is part of Cadmium.
 * Copyright (C) 2007-2010 Xavier Clerc.
 *
 * Cadmium is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Cadmium is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package fr.x9c.cadmium.support.values;

import fr.x9c.cadmium.kernel.Block;
import fr.x9c.cadmium.kernel.Value;

/**
 * This class defines values of the <i>'a * 'b * 'c * 'd</i> type.
 *
 * @param <T> type of first component
 * @param <U> type of second component
 * @param <V> type of third component
 * @param <W> type of fourth component
 * @param <X> type of fifth component
 *
 * @author <a href="mailto:cadmium@x9c.fr">Xavier Clerc</a>
 * @version 1.0
 * @since 1.0
 */
public final class Quintuple<T extends ToValue, U extends ToValue, V extends ToValue, W extends ToValue, X extends ToValue>
    implements ToValue {

    /** First component. */
    private final T v1;

    /** Second component. */
    private final U v2;

    /** Third component. */
    private final V v3;

    /** Fourth component. */
    private final W v4;

    /** Fifth component. */
    private final X v5;

    /**
     * Constructs a quadruple.
     * @param x1 first component - should not be <tt>null</tt>
     * @param x2 second component - should not be <tt>null</tt>
     * @param x3 third component - should not be <tt>null</tt>
     * @param x4 fourth component - should not be <tt>null</tt>
     * @param x5 fifth component - should not be <tt>null</tt>
     */
    public Quintuple(final T x1, final U x2, final V x3, final W x4, final X x5) {
        assert x1 != null : "null x1";
        assert x2 != null : "null x2";
        assert x3 != null : "null x3";
        assert x4 != null : "null x4";
        assert x5 != null : "null x5";
        this.v1 = x1;
        this.v2 = x2;
        this.v3 = x3;
        this.v4 = x4;
        this.v5 = x5;
    } // end constructor(T, U, V, W, X)

    /**
     * Returns the first component of the value.
     * @return the first component of the value
     */
    public T get1() {
        return this.v1;
    } // end method 'get1()'

    /**
     * Returns the second component of the value.
     * @return the second component of the value
     */
    public U get2() {
        return this.v2;
    } // end method 'get2()'

    /**
     * Returns the third component of the value.
     * @return the third component of the value
     */
    public V get3() {
        return this.v3;
    } // end method 'get3()'

    /**
     * Returns the fourth component of the value.
     * @return the fourth component of the value
     */
    public W get4() {
        return this.v4;
    } // end method 'get4()'

    /**
     * Returns the fifth component of the value.
     * @return the fifth component of the value
     */
    public X get5() {
        return this.v5;
    } // end method 'get5()'

    /**
     * {@inheritDoc}
     */
    @Override
    public Value toValue() {
        final Block res = Block.createBlock(5, 0);
        res.set(0, this.v1.toValue());
        res.set(1, this.v2.toValue());
        res.set(2, this.v3.toValue());
        res.set(3, this.v4.toValue());
        res.set(4, this.v5.toValue());
        return Value.createFromBlock(res);
    } // end method 'toValue()'

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return this.v1.hashCode()
            + this.v2.hashCode()
            + this.v3.hashCode()
            + this.v4.hashCode()
            + this.v5.hashCode();
    } // end method 'hashCode()'

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(final Object obj) {
        if (obj instanceof Reference) {
            final Quintuple<?, ?, ?, ?, ?> that = (Quintuple<?, ?, ?, ?, ?>) obj;
            return this.v1.equals(that.v1)
                && this.v2.equals(that.v2)
                && this.v3.equals(that.v3)
                && this.v4.equals(that.v4)
                && this.v5.equals(that.v5);
        } else {
            return false;
        } // end if/else
    } // end method 'equals(Object)'

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "(" + this.v1.toString()
            + ", " + this.v2.toString()
            + ", " + this.v3.toString()
            + ", " + this.v4.toString()
            + ", " + this.v5.toString() + ")";
    } // end method 'toString()'

} // end class 'Quintuple'
